﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Space_Conquest
{
    class InputManager : IInput 
    {

        /// <summary>
        /// List of IInput objects to take input
        /// </summary>
        private List<IInput> inputObjects = new List<IInput>();

        /// <summary>
        /// Adds an IInput object to the end of the list
        /// </summary>
        /// <param name="newObject"></param>
        public void Add(IInput newObject)
        {
            inputObjects.Add(newObject);
        }

        #region IInput Members

        public bool MouseDown(System.Windows.Forms.MouseButtons button, int x, int y)
        {

            // Pass event to every object in list
            foreach(IInput inputObj in inputObjects)
            {
                // If any object in List uses event, stop and return true
                if (inputObj.MouseDown(button, x, y))
                {
                    return true;
                }
            }

            // No objects in list used this event, return false
            return false;
        }

        public bool MouseUp(System.Windows.Forms.MouseButtons button, int x, int y)
        {

            // Pass event to every object in list
            foreach (IInput inputObj in inputObjects)
            {
                // If any object in List uses event, stop and return true
                if (inputObj.MouseUp(button, x, y))
                {
                    return true;
                }
            }

            // No objects in list used this event, return false
            return false;
        }

        public bool MouseMove(int x, int y)
        {

            // Pass event to every object in list
            foreach (IInput inputObj in inputObjects)
            {
                // If any object in List uses event, stop and return true
                if (inputObj.MouseMove(x,y))
                {
                    return true;
                }
            }

            // No objects in list used this event, return false
            return false;
        }

        public bool KeyDown(System.Windows.Forms.Keys key, bool shift)
        {

            // Pass event to every object in list
            foreach (IInput inputObj in inputObjects)
            {
                // If any object in List uses event, stop and return true
                if (inputObj.KeyDown(key,shift))
                {
                    return true;
                }
            }

            // No objects in list used this event, return false
            return false;
        }

        public bool KeyUp(System.Windows.Forms.Keys key, bool shift)
        {

            // Pass event to every object in list
            foreach (IInput inputObj in inputObjects)
            {
                // If any object in List uses event, stop and return true
                if (inputObj.KeyUp(key,shift))
                {
                    return true;
                }
            }

            // No objects in list used this event, return false
            return false;
        }

        #endregion
    }
}
